home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12808 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.0 KB  |  42 lines

  1. Path: dinews.epfl.ch!usenet
  2. From: Bernhard Ruch <Bernhard.Ruch@studi.epfl.ch>
  3. Newsgroups: comp.lang.c++,gnu.g++.help
  4. Subject: Template function only for built-in types
  5. Date: Thu, 21 Mar 1996 21:21:12 +0100
  6. Organization: Ecole Polytechnique Federale de Lausanne
  7. Message-ID: <3151BA38.41C6@studi.epfl.ch>
  8. NNTP-Posting-Host: didec6.epfl.ch
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.01 (X11; I; OSF1 V3.2 alpha)
  13.  
  14. Is it possible to declare a template function that is
  15. valid only for the built-in types, but not for classes
  16. created by the user?
  17.  
  18. I wanted to write the following template function:
  19.  
  20.  
  21.   template <class T> InStream &operator >> (InStream &pInStream, T &t) {
  22.  
  23.     cin >> t;
  24.  
  25.     return (pInStream);
  26.  
  27.   }; //* operator >> *//
  28.  
  29.  
  30.   class A {...};
  31.  
  32.  
  33. However, the compiler did not accept this, since the class istream
  34. contains no operator >> for the class A.
  35.  
  36. I got the following message:
  37.  
  38.   Test.h:103: no match for `operator >>(class istream, class A)'
  39.  
  40.  
  41. Bernhard
  42.